let dataCheck: DataCheck = {
	addDataCheck: (check: Run) => {
		console.debug("run addDataCheck");
		runChain.push(check);
	},
	clearDataCheck: () => {
		console.debug("run clearDataCheck");
		runChain = [];
	},
	checkAll: () => {
		console.debug("run checkAll",runChain);
		let success = true;
		for (let run of runChain) {
			if (!run()) {
				success = false;
				// return false;
			}
		}

		return success;
	},
};

export default function useDataCheck(): DataCheck {
	return dataCheck;
}

type Run = () => boolean;

export declare interface DataCheck {
	addDataCheck: (check: Run) => void;
	clearDataCheck: () => void;
	checkAll: () => boolean;
}

export declare interface DataStruc {
	id?: string | number;
	groupId?: string | number;
	name: string;
	viewName: string;
	type: number;
	dataSource: string;
	hint: string;
	defaultValue: string | number;
	length: number | null;
	minvalue: number | null;
	maxValue: number | null;
	rangx: string | null;
	must: boolean;
	errorHit: string;
	value: any;
	columnWidth: string;

	options: Array<Option>; //绑定的数据。此数据需要根据数据对象去获取。
	listView: number,//列表时是否显示
	canUpdate: number,//指明在修改时是否允许修改。修改时显示依然由canShow指明是否显示
	insertShow: number,	//指明增加的时候是否显示
	canShow: number,//这个指明在显示明细的时候是否显示
	fixed: string | null;
}

let runChain: Array<Run> = [];

export declare type Option = Record<number | string, string>;
